package com.sxkiler.demo.seata.service.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

@LocalTCC  //表示TCC interface
public interface TCCAccountService {
    //标记TCC接口  指定commit和cancle方法
    @TwoPhaseBusinessAction(name = "accountService", commitMethod = "accountConfirm", rollbackMethod = "accountCancel")
    //BusinessActionContext是TCC事务中的上下文对象
    //BusinessActionContextParameter注解标记的参数会在上下文中传播，即能通过BusinessActionContext对象在commit方法及cancle方法中取到该参数值
    boolean accountTry(BusinessActionContext actionContext,
                       @BusinessActionContextParameter(paramName = "userId") Long userId,
                       @BusinessActionContextParameter(paramName = "price") Integer price);

    boolean accountConfirm(BusinessActionContext actionContext);

    boolean accountCancel(BusinessActionContext actionContext);
}
